package com.jus.player.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

import com.jus.player.entity.WatchHistory;

import java.util.List;

@Dao
public interface WatchHistoryDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertOrUpdate(WatchHistory history);

    @Query("SELECT * FROM watch_history WHERE video_id = :videoId and user_id = :userId")
    WatchHistory getByVideoIdAndUserId(long videoId, long userId);

    @Query("SELECT * FROM watch_history ORDER BY last_watch_time DESC")
    List<WatchHistory> getAll();

    @Query("SELECT * FROM watch_history where user_id = :userId ORDER BY last_watch_time DESC")
    List<WatchHistory> getAllByUserId(long userId);

    @Delete
    void delete(WatchHistory history);

    @Query("DELETE FROM watch_history WHERE video_id = :videoId and user_id = :userId")
    void deleteByVideoIdAndUserId(long videoId, long userId);

}
